package com.jintian.smart.platform.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.jintian.smart.kernel.core.domain.ResponseDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import com.jintian.smart.base.api.system.constant.SystemSwaggerTagConst;
import com.jintian.smart.base.api.system.form.RoleMenuUpdateForm;
import com.jintian.smart.base.api.system.view.RoleMenuTreeVO;
import com.jintian.smart.platform.system.service.RoleMenuService;
import org.springframework.web.bind.annotation.*;

/**
 * 角色的菜单
 */
@RestController
@Tag(name = SystemSwaggerTagConst.SYSTEM_ROLE_MENU)
@RequestMapping("/sys/role/menu")
public class RoleMenuController {
    @Resource
    private RoleMenuService roleMenuService;

    @Operation(summary = "更新角色权限")
    @PostMapping("/updateRoleMenu")
    @SaCheckPermission("system:role:menu:update")
    public ResponseDTO<String> updateRoleMenu(@Valid @RequestBody RoleMenuUpdateForm updateDTO) {
        return roleMenuService.updateRoleMenu(updateDTO);
    }

    @Operation(summary = "获取角色关联菜单权限")
    @GetMapping("/getRoleSelectedMenu/{roleId}")
    public ResponseDTO<RoleMenuTreeVO> getRoleSelectedMenu(@PathVariable Long roleId) {
        return roleMenuService.getRoleSelectedMenu(roleId);
    }
}
